<?php
namespace Admin\Controller;
use Think\Controller;
class ArticleController extends CommonController{
	//显示文章
	private $_model;
	function _initialize(){
		$this->_model=D('Article');
	}
	public function index(){
		$data=D('Article')->get_data();
//		$data=M('Article')->query('SELECT * FROM tp_article,tp_category WHERE tp_article.category_cid=tp_category.cid');
		$data=M('Article')->query('SELECT * FROM tp_article LEFT OUTER JOIN tp_category ON tp_article.category_cid=tp_category.cid');

//		$data1=D('ArticleTagView')->get_data();
		$this->assign('data',$data);
		$this->display();
	}
	
	//添加文章
	public function add(){
		if(IS_POST){
  			$this->_model->add_data();


		};
		//分类
		$title=D('Category')->get_data();
		$this->assign('title',$title);

		//标签
		$tag=D('Tag')->get_data();
		$this->assign('tag',$tag);
		$this->display();
	}


	//上传缩略图

	public function upload(){
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize = 3145728 ;// 设置附件上传大小
		$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->rootPath = './Uploads/'; // 设置附件上传根目录
		$upload->savePath = ''; // 设置附件上传（子）目录
		// 上传文件
		$info = $upload->upload();
		if(!$info) {// 上传错误提示错误信息
			$this->error($upload->getError());
		}else{// 上传成功
//			$this->success('上传成功！');
			return $info;
		}
	}

	//回收站
	public function recycle(){
		$this->display();
	}

	public function edit(){
		if(IS_POST){

			$data=D('Article')->save_data();
			$this->error('修改成功');
		}
		$aid=I('get.aid');
		$where=array('aid'=>$aid);
		//文章表
		$arc=$this->_model->get_data($where);

		$arc['attr']=explode(',',$arc['attr']);
		$this->assign("arc",$arc);

		//标签表
		$tag=D('Tag')->get_data();
		$this->assign('tag',$tag);

		//文章数据
		$arcdata=D('ArticleData')->get_data(array('article_aid'=>$aid));
		$this->assign('arcdata',$arcdata);
		//获得所选择的标签
		$where=array('article_aid'=>$aid);
//		$tagchecked=M('ArticleTag')->query("SELECT tag_tid FROM tp_article_tag WHERE article_aid=$aid");
		$tagtid=D('ArticleTag')->get_data(array('article_aid'=>$aid));
		$this->assign('tagtid',$tagtid);

		$cate=D('Category')->get_data();
		$this->assign('cate',$cate);
		$this->assign("aid",$aid);

		$this->display();
	}

	public function del(){

		echo 456;
	}
}



?>